package Test16;

//静态代码块

public class Test03 {
    public static void main(String[] args) {
        //创建对象
        Student03 s1 = new Student03();

        Student03 s2 = new Student03("zhangsan", 23);
    }
}

class Student03 {
    private String name;
    private int age;

    //静态代码块
    //执行时机：随着类的加载而加载的，并且只执行一次。
    static {
        System.out.println("静态代码块执行了");
    }

    public Student03() {
        System.out.println("空参构造");
    }

    public Student03(String name, int age) {
        System.out.println("有参构造");
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
